/*
 * Copyright (c) 2013 WDCY Information Technology Co. Ltd
 * www.wdcy.cc
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * WDCY Information Technology Co. Ltd ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you
 * entered into with WDCY Information Technology Co. Ltd.
 */
package com.monkey.web.dto.response.monitor;


import org.hibernate.metadata.ClassMetadata;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author Wu Tianqiang
 */
public class ClassMetadataJSONDto {
    private String key;
    private String entityName;
    private String identifierProperty;

    public ClassMetadataJSONDto(String key, ClassMetadata classMetadata) {
        this.key = key;
        this.entityName = classMetadata.getEntityName();
        this.identifierProperty = classMetadata.getIdentifierPropertyName();
    }

    public static List<ClassMetadataJSONDto> toJSONDto(Map<String, ClassMetadata> allClassMetadata) {
        List<ClassMetadataJSONDto> classMetadataJSONDtos = new ArrayList<>();
        Set<String> keySet = allClassMetadata.keySet();
        for (String key : keySet) {
            classMetadataJSONDtos.add(new ClassMetadataJSONDto(key, allClassMetadata.get(key)));
        }
        return classMetadataJSONDtos;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getEntityName() {
        return entityName;
    }

    public void setEntityName(String entityName) {
        this.entityName = entityName;
    }

    public String getIdentifierProperty() {
        return identifierProperty;
    }

    public void setIdentifierProperty(String identifierProperty) {
        this.identifierProperty = identifierProperty;
    }
}